Back to Editorials CodeCraft
  • Github
  • Instagram
< >

Multiple Adder

TIME LIMIT = 5 SECS.

  • List all the natural numbers below N that are multiples of x or y. Print the sum of these multiples . . .

    Examples:
    The multiples of 3 and 5 below 100 are 3,6,9,5,10,12,15 etc.
    The sum of these multiples is 2318.
Input Output
The first line consists of x,y,n where the multiples
of x and y are checked till n.
The output consists of sum of the multiples of x and y

Example Test Case
Input              Output
3 5 100 2318
Solution

#include <stdio.h> int main() { long int i, sum = 0; int x, y, n; /* 'x' = value of x 'y' = value of y 'n' = value of n 'sum' = sum of all multiples of x and y below n 'i' = looping variable. */ /* Accept X, Y and N. N is the upper bound. Multiples of X and Y should be checked till N. */ scanf("%d %d %d", & x, & y, & n); for (i = 1; i <= n; i++) { //Check if the number is a multiple or not. if (i % x == 0 || i % y == 0) //Add it the 'sum' variable. sum += i; } //Print the sum. printf("%ld", sum); return 0; }
  • #1 Squared and cubic
  • #2 Digits
  • #3 Multiple Adder
  • #4 Grains in a Chessboard
  • #5 Age In Days
  • #6 Stay or Go
  • #7 Cipher

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();